import 'package:kepu/model/animal_list_entity.dart';
import 'package:kepu/util/http_util.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

part 'animal_list_provider.g.dart';

@riverpod
class AnimalListProvider extends _$AnimalListProvider {
  int page = 1;
  @override
  FutureOr<List<AnimalListDataRecords>> build() async {
    var response = await DioInstance.instance().get(
      path: "animal/list?current=1&size=10",
    );

    return AnimalListEntity.fromJson(response.data).data.records;
  }

  Future<void> add() async {
    page ++;
    var response = await DioInstance.instance().get(
      path: "animal/list?current=$page&size=10",
    );
    var records = AnimalListEntity.fromJson(response.data).data.records;
    if(records.isNotEmpty){
      state = AsyncValue.data([...state.value!,...records]);
    }
  }
}
